<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>组织机构管理</title>
		<link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css" />
		<link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css" />
	</head>
	<body class="wrap-container clearfix">
	<div class="column-content-detail">
		<form class="layui-form">
			<div class="search-cont clearfix" id="tool">
				<div class="operation-btn-cont">
					<div class="operright cyt-retract-close hideMenu">
						收起筛选<i class="iconfont">&#xe658;</i>
					</div>
					<div class="operright cyt-retract-open showMenu" style="display: none;">
						展开筛选<i class="iconfont">&#xe936;</i>
					</div>
					<@shiro.hasPermission name="sys:role:add">
					<button class="layui-btn layui-btn-normal layui-btn-mid " type="button" data-tab-name="组织机构添加"  id="organizationAddOrEdit" ><i class="iconfont marr5">&#xe65e;</i>添加</button>
				</@shiro.hasPermission>
				<button class="layui-btn layui-btn-normal layui-btn-mid down-all" type="button"><i class="iconfont marr5">&#xe6a6;</i>展开</button>
				<button class="layui-btn layui-btn-normal layui-btn-mid up-all" type="button"><i class="iconfont marr5">&#xe66f;</i>收起</button>

				<div class="triangle-bottom"></div>
			<div class="triangle-top"></div>
	</div>
	<div class="search-details">
		<div class="layui-form-item marb5">
			<div class="layui-inline">
				<label class="layui-form-label w75">组织机构名称：</label>
				<div class="layui-input-inline">
					<input type="text" name="name" id="name" placeholder="请输入组织机构名称" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label w75">状态：</label>
				<div class="layui-input-inline">
					<select name="status" id="status">

					</select>
				</div>
			</div>
			<div class="layui-inline marl8">
				<button class="layui-btn layui-btn-normal" type="button" lay-submit="" id="seacherBtn">搜索</button>
				<button class="layui-btn layui-btn-normal" type="reset" >重置</button>
			</div>
		</div>
	</div>
	</div>
	</form>
			<div class="layui-form" id="table-list">
				<table lay-filter="entityList" class="layui-table layui-formcy-list-table" id="test-tree-table"></table>
			</div>

	</div>
	<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
	<script>
        layui.use(['jquery','treetable','form','baseutil','page'],function(){
            var $ = layui.jquery,baseutil = layui.baseutil;
            var treetable = layui.treetable;
            var page = layui.page;
            var form = layui.form,layer = layui.layer;
            page.initDict("base_status", function (dictData) {
                page.showDict($("#status"), page.aceeptDictContentList(dictData, "base_status"), "请选择状态");
                var renderTable =function () {
                    var name = $('#name').val();
                    var status = $('#status').val();
                    baseutil.post("/sysOrganization/list", {"name": name,"status":status}, function (result) {
                        var data = [];
                        if (0 == result.code) {
                            for (var i = 0; i < result.data.length; i++) {
                                var obj = result.data[i];
                                var d = {};
                                d.id = obj.id;
                                d.name = obj.name;
                                if (obj.parentId == null || obj.parentId == "" || (name != null && name != "")) {
                                    d.pid = 0;
                                } else {
                                    d.pid = obj.parentId;
                                }
                                d.sort = obj.sort;
                                d.code = obj.code;
                                d.status =page.aceeptDictContentName(dictData,"base_status",obj.status);
                                data.push(d);
                            }
                            treetable.render({
                                elem: '#test-tree-table',
                                data: data,
                                field: 'name',
                                is_checkbox: true,
                                cols: [
                                    {
                                        field: 'name',
                                        title: '组织机构名称',
                                        width: '25%'
                                    }, {
                                        field: 'sort',
                                        title: '排序',
                                        width: '10%'
                                    }, {
                                        field: 'code',
                                        title: '组织机构code',
                                        width: '20%'
                                    }, {
                                        field: 'status',
                                        title: '状态',
                                        width: '20%', templet:function(d){
                                            if(d.status=="1"){
                                                return '<span class="status-green">'+page.aceeptDictContentName(dictData,"base_status",d.status)+'</span>';
                                            }else {
                                                return '<span class="status-grey">'+page.aceeptDictContentName(dictData,"base_status",d.status)+'</span>';
                                            }
                                        }
                                    }, {
                                        title: '操作',
                                        width: '25%',
                                        template: function () {
                                            var tem = [];
                                            tem.push('<a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-purple"  lay-filter="add">添加</a>');
                                            tem.push('<a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-green"  lay-filter="edit">编辑</a>');
                                            tem.push('<button class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-red" lay-filter="delete">删除</button>');
                                            return tem.join(' <font> </font> ')
                                        },
                                    }
                                ]
                            });
                        } else {
                            top.layer.msg(result.msg);
                        }
                    });
                    treetable.on('treetable(add)', function (data) {
                        page.editPopup("/sysOrganization/getAdd?id=" + data.item.id, "组织机构添加","560px","420px");
                        console.dir(data);
                    });

                    treetable.on('treetable(edit)', function (data) {
                        page.editPopup("/sysOrganization/getEdit?id=" + data.item.id, "组织机构编辑","560px","420px");
                        console.dir(data);
                    });
                    treetable.on('treetable(delete)', function (data) {
                        page.delete("/sysOrganization/delete", {
                            "id": data.item.id,
                            "_method": "DELETE"
                        }, "确定删除组织机构吗？", function (data) {
                            top.layer.msg(data);
                            renderTable();
                        });
                    });

                    //监听行工具事件
                    treetable.on('tool(test-tree-table)', function (obj) {
                        var layEvent = obj.event,
                            data = obj.data;
                        if (layEvent === 'del') { //删除
                            page.delete("/sysOrganization/delete", {
                                "id": data.item.id,
                                "_method": "DELETE"
                            }, "确定删除组织机构吗？", function (data) {
                                top.layer.msg(data);
                                renderTable();
                            });
                        }
                    });

                    form.on('switch(status)', function (data) {
                        layer.msg('监听状态操作');
                        console.dir(data);
                    })
                };
                renderTable();

                $('#seacherBtn').click(function(){
                    renderTable();
                });

                $('.up-all').click(function(){
                    treetable.all('up');
                });

                $('.down-all').click(function(){
                    treetable.all('down');
                });

                $('.get-checked').click(function(){
                    console.dir(treetable.all('checked'));
                });
            });

            $("#organizationAddOrEdit").bind("click",function () {
                page.editPopup("/sysOrganization/getAdd","组织机构添加");
            });
        });
	</script>
	</body>

</html>